#include "RealArraySolution.hh"

int RealArraySolution::size = 0;

double *RealArraySolution::higherBounds = NULL;
double *RealArraySolution::lowerBounds = NULL;


RealArraySolution::RealArraySolution(int *array): Solution() {
    this->array = new double[size];
    for (int i = 0; i < size; i++)
        this->array[i] = array[i];
}

RealArraySolution::RealArraySolution(): Solution() {
    array = new double[size];
}

RealArraySolution::~RealArraySolution() {
    delete [] array;
}

RealArraySolution::RealArraySolution(RealArraySolution &other): Solution(other) {

    array = new double[size];

    for (int i = 0; i < size; i++)
        array[i] = other.array[i];
}

double RealArraySolution::get(int i) {
    return array[i];
}

void RealArraySolution::set(int i, double value) {
    array[i] = value;
    changed = true;
}

void RealArraySolution::initialize() {

    for (int i = 0; i < size; i++) {

        if (lowerBounds == NULL || higherBounds == NULL)
            array[i] = Random::getInstance()->getReal(0.0, 1.0);
        else
            array[i] = Random::getInstance()->getReal(lowerBounds[i], higherBounds[i]);
    }

    ArrayList<Restriction> *restrictions = Solution::getRestrictions();
    if (restrictions != NULL) {
        for (int i = 0; i < restrictions->length(); i++)
            restrictions->get(i)->apply(this);

    }
}

int RealArraySolution::length() {
    return RealArraySolution::size;
}

void RealArraySolution::send(ostream &os) {
    for (int i = 0; i < length(); i++)
        os << " " << get(i);
    Solution::send(os);
}

Solution* RealArraySolution::copy() {
    return new RealArraySolution(*this);
}
